package com.jqb.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Http extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*Http*/
		/*1.访问方式
		 * http://localhost/ServletLab01/Http
		 * http是协议名称
		 * localhost是主机名称(默认端口为80)
		 * ServletLab01是应用名称
		 * Http是资源名称(本例中Http就是Servlet)
		 *2.访问流程
		 * a.本地浏览器提交URL地址
		 * b.浏览器从URL中解析出主机名称
		 * c.到本机Host文件中查找主机名对应的Ip,找不到就去DNS服务器找,再找不到直接报错
		 * d.找到Ip,连接对应的服务器,发送Http请求
		 * e.服务器接收请求,解析出浏览器想访问的主机名(因为可能一个IP对应多个主机)
		 * f.继续解析出想要访问的Web应用(一个主机中可以有多个WEB应用)
		 * g.继续解析出想要访问的具体资源
		 * h.读取资源
		 * i.发送数据
		 * */
		/*
		 * 两种输出流都可以发送数据,但是不能同时使用,会报如下错误
		 * */
		PrintWriter writer = response.getWriter();
		writer.println("http");
		
//		OutputStream out = response.getOutputStream();
//		out.write("http".getBytes());
	}
}
